package com.tzl.design_pattern.proxy_pattern;

/**
 * 代理对象
 *
 * @author Zhilei Tang
 * @date Created in 2020/11/16 20:26
 */
public class TravelAgency implements Travel {
  // 代理对象需要持有被代理对象
  private TravelPerson travelPerson;

  public TravelAgency(TravelPerson travelPerson) {
    this.travelPerson = travelPerson;
  }

  @Override
  public void buyTrainTicket() {
    before();
    this.travelPerson.buyTrainTicket();
    after();
  }

  /** 后置增强 */
  private void after() {
    System.out.println("付尾款");
  }

  /** 前置增强 */
  private void before() {
    System.out.println("付定金");
  }
}
